<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Example of edge detection, edge linking, and line segment fitting</title>
<link href="../../pkstylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>

<h2>Example of edge detection, edge linking, and line segment fitting</h2>

<hr>

<center>
<img src=shapessm.jpg>
</center>

<pre>
    % Read the sample image in
    im = imread('shapessm.jpg');
    
    % Find edges using the Canny operator with hysteresis thresholds of 0.1
    % and 0.2 with smoothing parameter sigma set to 1.
    edgeim = edge(im,'canny', [0.1 0.2], 1);

    figure(1), imshow(edgeim);
</pre>

<p><center>
<img src=edgeim.jpg>
</center>

<pre>    
    % Link edge pixels together into lists of sequential edge points, one
    % list for each edge contour. A contour/edgelist starts/stops at an 
    % ending or a junction with another contour/edgelist.
    % Here we discard contours less than 10 pixels long.

    [edgelist, labelededgeim] = edgelink(edgeim, 10);
    
    % Display the edgelists with random colours for each distinct edge 
    % in figure 2

    drawedgelist(edgelist, size(im), 1, 'rand', 2); axis off        

</pre>

<center>
<img src=edgelistim.jpg>
</center>

<pre>        
    % Fit line segments to the edgelists
    tol = 2;         % Line segments are fitted with maximum deviation from
		     % original edge of 2 pixels.
    seglist = lineseg(edgelist, tol);

    % Draw the fitted line segments stored in seglist in figure window 3 with
    % a linewidth of 2 and random colours
    drawedgelist(seglist, size(im), 2, 'rand', 3); axis off

</pre>

<center>
<img src=segmentim.jpg>
</center>

<hr>

</body>
</html>
